From 5f1014b41fab3ecb67e033e270e19060ad2af88f Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 22 Aug 2022 10:49:04 -0700 Subject: get user from data prop --- src/routes/[username]/+page.server.js | 11 +- src/routes/[username]/dashboard/+page.svelte | 160 ++++++++++++++------------- 2 files changed, 86 insertions(+), 85 deletions(-) (limited to 'src/routes/[username]') diff --git a/src/routes/[username]/+page.server.js b/src/routes/[username]/+page.server.js index 9ae4af2d..1bd8c434 100644 --- a/src/routes/[username]/+page.server.js +++ b/src/routes/[username]/+page.server.js @@ -3,20 +3,11 @@ import { get, post } from '$lib/utils'; export async function load({ params }) { let { username } = params; - let body; - - try { - body = await get(`/users/${username}`); - } catch (e) { - body = {}; - } - - return body; + return get(`/users/${username}`); } export async function PUT({ request }) { let { token } = cookie.parse(request.headers.get('cookie') || ''); let { user } = await request.json(); await post(`/user`, user, { authorization: `Bearer ${token}` }); - console.log('put done'); } diff --git a/src/routes/[username]/dashboard/+page.svelte b/src/routes/[username]/dashboard/+page.svelte index ef8bef88..e4f6538e 100644 --- a/src/routes/[username]/dashboard/+page.svelte +++ b/src/routes/[username]/dashboard/+page.svelte @@ -2,9 +2,12 @@ import { post, failure } from '$lib/utils'; import { tick } from 'svelte'; import { AppHeader, Icon } from '$comp'; - import { selectedRate, user } from '$lib/store'; + import { selectedRate } from '$lib/store'; import { t } from '$lib/translations'; + export let data; + $: user = data.user; + let payreq = '', payreqField, withdrawing; @@ -26,94 +29,101 @@ $: btcPrice = new Intl.NumberFormat('en-US', { style: 'currency', - currency: $user.currency + currency: user.currency }).format($selectedRate); $: accountBalanceFiat = new Intl.NumberFormat('en-US', { style: 'currency', - currency: $user.currency - }).format($user.account.balance * ($selectedRate / 100000000)); + currency: user.currency + }).format(user.account.balance * ($selectedRate / 100000000)); - $: accountBalanceBtc = $user.account.balance / 100000000; + $: accountBalanceBtc = user.account.balance / 100000000; $: accountBalanceSats = new Intl.NumberFormat('en-US', { maximumFractionDigits: 0 }).format( - $user.account.balance + user.account.balance ); -{#if $user} - + + +
+

{user.username}

+ {$t('user.addressGoesHere')} +
+ +
+
+

+ {withdrawing ? 'Withdraw' : 'Dashboard'} +

+ {#if !withdrawing} + {$t('user.dashboard.bitcoinPrice')} + {$selectedRate ? btcPrice : $t('user.dashboard.fetchingRate')} + + + {@html $t('user.dashboard.dataFromBinance')} + +

+ {$t('user.dashboard.ACCOUNT_BALANCE')} +

+ + {$selectedRate ? accountBalanceFiat : $t('user.dashboard.fetchingRate')} + + {accountBalanceSats} SAT + + +

{$t('user.dashboard.conversionFeeWarning')}

+ {:else} +
+ + +
+ + +
-
-

{$user.username}

- {$t('user.addressGoesHere')} -
+
+ +